home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / Clouseau libs / Errors.lib < prev    next >
Encoding:
Text File  |  1998-03-19  |  27.9 KB  |  731 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #########################################################################
  3. ##                     Copyright © Apple Computer, Inc. 1993-1997
  4. ##                                All rights reserved
  5. #########################################################################
  6. #########################################################################
  7. ##
  8. ##
  9. ##    WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! 
  10. ##    
  11. ##    THIS LIBRARY IS OBSOLETE. IT IS INCLUDED FOR BACKWARDS COMPATIBILITY.
  12. ##
  13. ##    IT WILL BE REMOVED IN FUTURE RELEASES OF THE CLOUSEAU LIBRARIES. 
  14. ##
  15. ##    DO NOT USE THIS LIBRARY IN NEW SCRIPTS. 
  16. ##
  17. ##    Use ExceptionHandling.lib in the SPEC Libraries instead of Errors.lib.
  18. ##
  19. ##
  20. #########################################################################
  21. #########################################################################
  22. #    Library:        Errors.lib
  23. #    
  24. #    Version:        2.1.4
  25. #    
  26. #    Description:    
  27. #        Contains tasks for script errors.
  28. #    
  29. #    Contains:
  30. #        ErrorHandler()
  31. #        EPushHandler()
  32. #        EPopHandler()
  33. #        EGetHandler()
  34. #        EClearCurrentError()
  35. #        ESuspendCurrentError()
  36. #        EResumeCurrentError()
  37. #        _match()
  38. #        _select()
  39. #        _type()
  40. #        _pressKey()
  41. #        _releaseKey()
  42. #        E_InitializeErrors()
  43. #    
  44. #    History:
  45. #        Date:        By:                Changes:
  46. #        06/15/93    SBR    Created for use with Launchquits (LQ Project)
  47. #        02/19/94    SBR                Moved to Clouseau Project for everyone to use
  48. #        05/25/94    SBR                Optimized _match(), added _matchBoolean()
  49. #        01/21/97    SBR                Updated copyright header.
  50. #    
  51. #########################################################################
  52. #########################################################################
  53.  
  54. Libraries 
  55.     "Report.lib";
  56.  
  57. #######################################################################################
  58. #    task                    ErrorHandler(errorIn, notErrors, v_level)
  59. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  60. #    Description:    Handle serious errors from the ScriptError() built-in task. A serious
  61. #                    error is one which causes script flow to change unexpectedly to
  62. #                    handle global problems like target crashes. The caller determines
  63. #                    which errors are serious by using the notErrors parameter, and what
  64. #                    to do for each error by pushing and popping items on the error
  65. #                    handler stack. You can simulate errors by passing values directly.
  66. #                    This task is designed for use by a VU library's primitives.
  67. #    Parameters:        errorIn:    The result of ScriptError() for a command statement.
  68. #                        Note:    You can not call ScriptError() inside a task to check the 
  69. #                        statement which preceded the task call. If you do, ScriptError() 
  70. #                        returns zero because there was no error entering the task.
  71. #                    notErrors:    A list of error codes which should not be considered 
  72. #                                serious errors this time. E.g.: for _match(), -1105 is a
  73. #                                simple match failure. Script flow continues, _match 
  74. #                                returns [] and whoever called _match will handle it.
  75. #    Returns:        { errorValue, errorString }
  76. #    Examples:        theError := ErrorHandler(ScriptError(), {-1105});
  77. #    Assumptions:    VU 2.0.1 (VU 2.1 desired for -1096 error handling, but not required)
  78. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  79. #    History:
  80. #        06/12/93    SBR        Created
  81. #        10/14/93    SBR        Fixed major bug by using gErrorsAreInitialized flag
  82. #        03/11/95    SBR        Added -1096 string
  83. #######################################################################################
  84. task    ErrorHandler(theError := 0, notErrors := {}, v_level := 4)
  85. begin
  86.     global gCurrentError, g_Trap_NoError, gErrorsAreInitialized;
  87.     
  88.     RStatus("ErrorHandler: theError: {theError}", v_level);
  89.  
  90.     if not gErrorsAreInitialized
  91.         E_InitializeErrors();
  92.  
  93.     if (not theError) and (not g_Trap_NoError)        # optimized for speed
  94.         return { 0,"no error" };
  95.     else if isMember(theError, notErrors)
  96.         return { 0,"error handling was supressed for {theError}" };        
  97.  
  98.     if gCurrentError begin
  99.         ESuspendCurrentError();
  100.         pleaseResumeError := true;
  101.     end;
  102.     
  103.     if theError = -1100                                # It's Mr. Sluggo! Oh, noooo!!!! 
  104.         gCurrentError := {theError, "Target is crashed or disconnected"};
  105.     else if theError = -1096                        # VU 2.1 detected a new Agent "ID"
  106.         gCurrentError := {theError, "Target restarted unexpectedly"};
  107.     else 
  108.         gCurrentError := {theError, "unknown reason"};
  109.  
  110.     theHandler := EGetHandler(theError);
  111.     if not theHandler
  112.         theResult := {theError, "no handler or string exists for error value {theError}"};
  113.     else begin
  114.         theTask := theHandler[1];
  115.         if theTask begin
  116.             error_v_level := theHandler[3];
  117.             if not error_v_level
  118.                 error_v_level := v_level;
  119.             theResult := { theError,call(theTask, theError, theHandler[2], error_v_level) };
  120.         end;
  121.         else begin
  122.             theString := theHandler[2];
  123.             theResult := {theError, theString};
  124.         end;
  125.     end;
  126.  
  127.     if pleaseResumeError begin
  128.         EResumeCurrentError();
  129.     end;
  130.  
  131.     RStatus("ErrorHandler: theResult: {theResult}", v_level);
  132.     return theResult;
  133. end;
  134.  
  135.  
  136. #########################################################################
  137. #    task                    EPushHandler(theError, theHandler, v_level)
  138. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  139. #    Description:    Appends an item to the beginning of the global variable 
  140. #                    gUserErrorVectorTable, so assoc() in EGetHandler() finds it first.
  141. #    Parameters:        theError: the key error value used by assoc to look up the handler
  142. #                    theHandler:    the handler to execute; See the E_InitializeErrors() 
  143. #                                routine for the format of an errorHandler. 
  144. #                    v_level:    Verbosity level for reporting
  145. #    Returns:        true if it worked, false if not
  146. #    Examples:        EPushHandler(-1100, { task crashRecover,{ "TeachText",1,5 }});
  147. #    Assumptions:    VU 2.0.1
  148. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  149. #    History:
  150. #        06/12/93    SBR        Created
  151. #        10/14/93    SBR        Fixed major bug by using gErrorsAreInitialized flag
  152. #########################################################################
  153. task    EPushHandler(theError, theHandler, v_level := 4)
  154. begin
  155.     global gUserErrorVectorTable, g_Trap_NoError, gErrorsAreInitialized;
  156.     
  157.     if not gErrorsAreInitialized
  158.         E_InitializeErrors();
  159.  
  160.     gUserErrorVectorTable := {{theError, theHandler}} + gUserErrorVectorTable;
  161.     
  162.     temp := ScriptError();
  163.     if not temp begin
  164.         if theError = 0        # handling No Error is weird - usually we skip it for speed
  165.             g_Trap_NoError := true;
  166.             
  167.         return true;
  168.     end;
  169.     return RIncomplete("EPushHandler: ScriptError {theError} while pushing {theHandler}", v_level);
  170. end;
  171.  
  172.  
  173. #########################################################################
  174. #    task                    EPopHandler(theError, v_level)
  175. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  176. #    Description:    Remove an item from the global variable gUserErrorVectorTable. See 
  177. #                    the E_InitializeErrors() routine for the format of an item. If an
  178. #                    item already exists for that error it is replaced.
  179. #    Parameters:        errorHandler:    the item to put in the list
  180. #                    v_level:    Verbosity level for reporting
  181. #    Returns:        true if set worked, false if not
  182. #    Examples:        EPopHandler(-1100);
  183. #    Assumptions:    VU 2.0.1
  184. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  185. #    History:
  186. #        06/12/93    SBR        Created
  187. #        10/14/93    SBR        Fixed major bug by using gErrorsAreInitialized flag
  188. #########################################################################
  189. task    EPopHandler(theError, v_level := 4)
  190. begin
  191.     global gUserErrorVectorTable, g_Trap_NoError, gErrorsAreInitialized;
  192.     
  193.     if not gErrorsAreInitialized
  194.         E_InitializeErrors();
  195.  
  196.     theItem := assoc(theError, gUserErrorVectorTable);
  197.     if not theItem
  198.         return RIncomplete("EPopHandler: No handler exists for {theError}", v_level);
  199.     else gUserErrorVectorTable := 
  200.         remove(isMember({theError,theItem}, gUserErrorVectorTable), gUserErrorVectorTable);
  201.     
  202.     temp := ScriptError();
  203.     if not temp begin
  204.         if theError = 0 
  205.             if not assoc(0,gUserErrorVectorTable) 
  206.                 g_Trap_NoError := false;        # usually skip No Error for speed
  207.         return true;
  208.     end;
  209.     return RIncomplete("EPopHandler: ScriptError {theError} while removing {theItem}", v_level);
  210. end;
  211.  
  212.  
  213. #########################################################################
  214. #    task                    EGetHandler(theError, v_level)
  215. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  216. #    Description:    Get the handler for an error. Looks first in the global variable 
  217. #                    gUserErrorStack, then in the global variable gErrorStack. 
  218. #                    See the E_InitializeErrors() routine for the format of a handler item.
  219. #    Parameters:        theError:    possible result from ScriptError() or any other value
  220. #                    v_level:    Verbosity level for reporting
  221. #    Returns:        the item in the variable gErrorStack
  222. #    Examples:        theCrashString := EGetHandler(-1100)[2];
  223. #    Assumptions:    VU 2.0.1
  224. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  225. #    History:
  226. #        06/12/93    SBR        Created
  227. #        10/14/93    SBR        Fixed major bug by using gErrorsAreInitialized flag
  228. #########################################################################
  229. task    EGetHandler(theError, v_level := 4)
  230. begin
  231.     global gErrorVectorTable, gUserErrorVectorTable, gErrorsAreInitialized;
  232.     
  233.     if not gErrorsAreInitialized
  234.         E_InitializeErrors();
  235.  
  236.     theItem := assoc(theError, gUserErrorVectorTable);
  237.     if theItem 
  238.         return theItem;
  239.         
  240.     theItem := assoc(theError, gErrorVectorTable);
  241.     if theItem 
  242.         return theItem;
  243.     
  244.     RIncomplete("EGetHandler: {theError} is an unknown error",v_level);
  245.     return {};
  246. end;
  247.  
  248.  
  249. #########################################################################
  250. #    task                    EClearCurrentError(v_level)
  251. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  252. #    Description:    Since _match and the other super-primitives will not attempt target 
  253. #                    communication if there is a current error, an error handler 
  254. #                    which uses them must clear the error first. This task puts an empty 
  255. #                    list into gCurrentError, and should only be called by the routine
  256. #                    that actually fixes the problem. To clear the current error 
  257. #                    temporarily within a handler, call E_SuspendCurrentError() near the
  258. #                    beginning and E_ResumeCurrentError() near the end of your routine.
  259. #    Parameters:        v_level:    Verbosity level for reporting
  260. #    Returns:        true
  261. #    Examples:        E_ClearCurrentError();    # this handler will fix the problem
  262. #    Assumptions:    VU 2.0.1
  263. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  264. #    History:
  265. #        06/23/93    SBR        Created
  266. #########################################################################
  267. task    EClearCurrentError(v_level := 5)
  268. begin
  269.     global gCurrentError;
  270.     
  271.     RStatus("EClearCurrentError: gCurrentError was {gCurrentError}", v_level);
  272.     gCurrentError := {};
  273. end;
  274.  
  275.  
  276. #########################################################################
  277. #    task                    ESuspendCurrentError(v_level)
  278. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  279. #    Description:    Since _match and the other super-primitives will not attempt target 
  280. #                    communication if there is a current error, an error handler 
  281. #                    which uses them must suspend the error first. This task pushes 
  282. #                    gCurrentError onto the gPreviousErrorStack, and puts an empty 
  283. #                    list into gCurrentError. When the handler is finished it 
  284. #                    should call EResumeCurrentError(). 
  285. #                    NOTE: If a handler completely fixes the error it should 
  286. #                    call EClearCurrentError() instead of ESuspendCurrentError()
  287. #                    and EResumeCurrentError().
  288. #    Parameters:        v_level:    Verbosity level for reporting
  289. #    Returns:        true
  290. #    Examples:        ESuspendCurrentError();
  291. #    Assumptions:    VU 2.0.1, gPreviousErrorStack is initialized
  292. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  293. #    History:
  294. #        06/23/93    SBR        Created
  295. #########################################################################
  296. task    ESuspendCurrentError(v_level := 5)
  297. begin
  298.     global gCurrentError, gPreviousErrorStack;
  299.     
  300.     gPreviousErrorStack := {gCurrentError} + gPreviousErrorStack;
  301.     RStatus("ESuspendCurrentError: gCurrentError was {gCurrentError}", v_level);
  302.     gCurrentError := {};
  303. end;
  304.  
  305.  
  306. #########################################################################
  307. #    task                    EResumeCurrentError(restoreIt, v_level)
  308. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  309. #    Description:    After calling ESuspendCurrentError(), an error handler task must 
  310. #                    call EResumeCurrentError() so subsequent _match calls fail until
  311. #                    a higher level routine fixes the problem. 
  312. #    Parameters:        restoreIt:    true:    Restore gCurrentError to its previous state.
  313. #                                        Subsequent calls to _match (et al) will fail 
  314. #                                        until a routine solves the problem, then 
  315. #                                        calls EResumeCurrentError(false).
  316. #                                false:    Pop the previous error off the stack, but
  317. #                                        leave gCurrentError empty. Do not use false 
  318. #                                        until the problem has been completely fixed.
  319. #                    v_level:    Verbosity level for reporting
  320. #    Returns:        true
  321. #    Examples:        EResumeCurrentError(true);        # let someone else fix the problem
  322. #                    EResumeCurrentError(false);        # we fixed the problem already
  323. #    Assumptions:    VU 2.0.1, gPreviousErrorStack is initialized
  324. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  325. #    History:
  326. #        06/23/93    SBR        Created
  327. #########################################################################
  328. task    EResumeCurrentError(restoreIt, v_level := 5)
  329. begin
  330.     global gCurrentError, gPreviousErrorStack;
  331.     
  332.     if gPreviousErrorStack begin
  333.         temp := gPreviousErrorStack[1];
  334.         gPreviousErrorStack := remove(1, gPreviousErrorStack);
  335.     end;
  336.     if restoreIt and temp
  337.         gCurrentError := temp;
  338.     else gCurrentError := {};
  339.     RStatus("EResumeCurrentError: gCurrentError is now {gCurrentError}", v_level);
  340. end;
  341.  
  342.  
  343. #########################################################################
  344. #    task                    _match(desc, exact, notErrors, v_level)
  345. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  346. #    Description:    Match a descriptor and handle any script errors. If target crashed,
  347. #                    always return [] until gCurrentError is reset.
  348. #    Parameters:        theDesc:    the descriptor to match; add ! for exact
  349. #                    exact:        true for exact (!)
  350. #                    notErrors:    passed to ErrorHandler
  351. #                    v_level:    verbosity level for reporting
  352. #    Returns:        same as match
  353. #    Examples:        theTarget := _match([target]);
  354. #                    myCheckBox := _match([checkBox o:3 w:2 s:{ 0,1 }], { true });
  355. #    Assumptions:    VU 2.0.1
  356. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  357. #    History:
  358. #        06/12/93    SBR        Created
  359. #        05/25/94    SBR        Call ErrorHandler only if ScriptError <> 0 or -1105
  360. #########################################################################
  361. task    _match(theDesc := [target], exact := false, notErrors := {-1105}, v_level := 4)
  362. begin
  363.     if global gCurrentError begin
  364.         RIncomplete("_match: current error ({gCurrentError}) - did not try match",v_level);
  365.         return [];
  366.     end;
  367.  
  368.     if exact theMatch := match theDesc!;        # To ensure ScriptError() works, this statement 
  369.     else theMatch := match theDesc;                # must not be first in the task.
  370.  
  371.     theError := ScriptError();
  372.     if (theError = 0) 
  373.         return theMatch;                        # 0 = match occurred
  374.     if (theError = -1105) AND isMember(-1105, notErrors)
  375.         return theMatch;                        # -1105 = simple match failure
  376.     else theError := ErrorHandler(theError, notErrors, v_level);        # a real problem
  377.     
  378.     if R_BeVerbose(v_level) begin
  379.         if theError[1]
  380.             RIncomplete("_match: Error ({theError}) matching {theDesc}",v_level);
  381.         else RStatus("_match: Matched {theDesc} with {theMatch}",v_level);
  382.     end;
  383.     
  384.     return theMatch;
  385. end;
  386.  
  387.  
  388. #########################################################################
  389. #    task                    _matchBoolean(desc, exact, notErrors, v_level)
  390. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  391. #    Description:    Match a descriptor quickly and return true or false. This is useful 
  392. #                    with if statements, where you just want to know if the descriptor 
  393. #                    exists. It uses VU optimization to save time when matching descriptors 
  394. #                    that contain large lists, like control panel windows. Handles errors 
  395. #                    just like _match, except if theError is -1105 it returns false. If 
  396. #                    the target is crashed, return undefined until gCurrentError is reset. 
  397. #    Parameters:        theDesc:    the descriptor to match;
  398. #                    exact:        true for exact (!) match
  399. #                    notErrors:    passed to ErrorHandler only if error is not 0 or -1105
  400. #                    v_level:    verbosity level for reporting
  401. #    Returns:        true if match worked (ScriptError() = 0), 
  402. #                    false if not (ScriptError() = -1105), 
  403. #                    undefined if ErrorHandler() returns an error
  404. #    Examples:        targetIsAlive := _matchBoolean([mouse]);
  405. #                    featureIsOff := _matchBoolean([checkBox o:3 w:2 s:{ 0,1 }], true);
  406. #    Assumptions:    VU 2.0.1
  407. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  408. #    History:
  409. #        05/21/94    SBR        Created
  410. #        09/03/94    SBR        Changed exact default to true
  411. #########################################################################
  412. task    _matchBoolean(theDesc, exact := true, notErrors := {}, v_level := 4)
  413. begin
  414.     if global gCurrentError begin
  415.         RIncomplete("_matchBoolean: current error ({gCurrentError}) - did not try match",v_level);
  416.         return undefined;
  417.     end;
  418.     
  419.     if exact
  420.         match theDesc!;            # To ensure ScriptError() works, this statement 
  421.     else
  422.         match theDesc;            # must not be first in the task.
  423.  
  424.     theError := ScriptError();
  425.     if theError = 0
  426.         return true;                    # no error, match occurred
  427.     else if theError = -1105
  428.         return false;                    # -1105 means simple match failure
  429.     else theError := ErrorHandler(theError, notErrors, v_level);        # a real problem
  430.     
  431.     if R_BeVerbose(v_level) begin
  432.         if theError[1]
  433.             RIncomplete("_matchBoolean: Error ({theError}) matching {theDesc}",v_level);
  434.         else RStatus("_matchBoolean: Matched {theDesc} with {theMatch}",v_level);
  435.     end;
  436.     
  437.     return undefined;
  438. end;
  439.  
  440.  
  441. #########################################################################
  442. #    task                    _select(theDesc, exact, notErrors, v_level)
  443. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  444. #    Description:    Select a descriptor and handle any script errors. If target crashed,
  445. #                    always return false until gCurrentError is reset.
  446. #    Parameters:        theDesc:    the descriptor to select; add ! for exact
  447. #                    exact:        true for exact (!)
  448. #                    notErrors:    passed to ErrorHandler
  449. #                    v_level:    verbosity level for reporting
  450. #    Returns:        true/false for success/failure
  451. #                    NOTE: As of VU 2.0.1, the real select does not return a value
  452. #    Examples:        if not _select([menuItem 'Restart']) exit;
  453. #    Assumptions:    VU 2.0.1
  454. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  455. #    History:
  456. #        06/12/93    SBR        Created
  457. #########################################################################
  458. task    _select(theDesc, exact := false, notErrors := {}, v_level := 4)
  459. begin
  460.     global gCurrentError;
  461.     
  462.     if gCurrentError begin
  463.         RIncomplete("_select: current error ({gCurrentError}) - did not try select",v_level);
  464.         return false;
  465.     end;
  466.     
  467.     if exact select theDesc!;
  468.     else select theDesc;
  469.     
  470.     theError := ErrorHandler(ScriptError(), notErrors, v_level);
  471.     if theError[1]
  472.         theSelect := false;
  473.     else theSelect := true;
  474.     
  475.     if R_BeVerbose(v_level) begin
  476.         if not theSelect
  477.             RIncomplete("_select: Error ({theError}) selecting {theDesc}",v_level);
  478.         else RStatus("_select: Selected {theDesc}",v_level);
  479.     end;
  480.     
  481.     return theSelect;
  482. end;
  483.  
  484.  
  485. #########################################################################
  486. #    task                    _type(keyList, codeList, pad, notErrors, v_level)
  487. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  488. #    Description:    Type a list of keys and/or character codes. If target crashed,
  489. #                    always return false until gCurrentError is reset.
  490. #    Parameters:        keyList:    the keys to type
  491. #                    codeList:    the character codes to type
  492. #                    pad:        use or do not use the keyPad
  493. #                    notErrors:    passed to ErrorHandler
  494. #                    v_level:    verbosity level for reporting
  495. #    Returns:        true/false for success/failure
  496. #                    NOTE: As of VU 2.0.1, the real type does not return a value
  497. #    Examples:        if not _type({returnKey},{20},{-1170})[2] println "Typing failed";
  498. #    Assumptions:    VU 2.0.1
  499. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  500. #    History:
  501. #        06/12/93    SBR        Created
  502. #########################################################################
  503. task    _type(    keyList := {}, codeList := {}, pad := undefined, notErrors := {}, 
  504.                 v_level := 4 )
  505. begin
  506.     global gCurrentError;
  507.     
  508.     if gCurrentError begin
  509.         RIncomplete("_type: current error ({gCurrentError}) - did not try typing",v_level);
  510.         return false;
  511.     end;
  512.     
  513.     if isUndefined(pad) begin
  514.         if codeList
  515.             if keyList type c:codeList k:keyList;
  516.             else type c:codeList;
  517.         else type k:keyList;
  518.     end;
  519.     else begin
  520.         if codeList
  521.             if keyList type c:codeList k:keyList p:pad;
  522.             else type c:codeList p:pad;
  523.         else type k:keyList p:pad;
  524.     end;
  525.     
  526.     theError := ErrorHandler(ScriptError(), notErrors, v_level);
  527.     if theError[1]
  528.         theType := false;
  529.     else theType := true;
  530.     
  531.     if R_BeVerbose(v_level) begin
  532.         typeString := "c:{codeList} k:{keyList} p:{pad}";
  533.         if not theType
  534.             RIncomplete("_type: Error ({theError}) typing {typeString}",v_level);
  535.         else RStatus("_type: Typed {typeString}",v_level);
  536.     end;
  537.     
  538.     return theType;
  539. end;
  540.  
  541.  
  542. #########################################################################
  543. #    task                    _pressKey(keyList, codeList, pad, notErrors, v_level)
  544. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  545. #    Description:    Press a list of keys and/or character codes. If target crashed,
  546. #                    always return false until gCurrentError is reset.
  547. #    Parameters:        keyList:    the keys to press
  548. #                    codeList:    the character codes to press
  549. #                    pad:        use or do not use the keyPad
  550. #                    notErrors:    passed to ErrorHandler
  551. #                    v_level:    verbosity level for reporting
  552. #    Returns:        true/false for success/failure
  553. #                    NOTE: As of VU 2.0.1, the real pressKey does not return a value
  554. #    Examples:        if not _pressKey({shiftKey},{20},{-1170}) println "pressKey failed";
  555. #    Assumptions:    VU 2.0.1
  556. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  557. #    History:
  558. #        06/12/93    SBR        Created
  559. #########################################################################
  560. task    _pressKey(    keyList := {}, codeList := {}, pad := undefined, notErrors := {}, 
  561.                     v_level := 4)
  562. begin
  563.     global gCurrentError;
  564.     
  565.     if gCurrentError begin
  566.         RIncomplete("_pressKey: current error ({gCurrentError}) - did not try pressing",v_level);
  567.         return false;
  568.     end;
  569.     
  570.     if isUndefined(pad) begin
  571.         if codeList
  572.             if keyList pressKey c:codeList k:keyList;
  573.             else pressKey c:codeList;
  574.         else pressKey k:keyList;
  575.     end;
  576.     else begin
  577.         if codeList
  578.             if keyList pressKey c:codeList k:keyList p:pad;
  579.             else pressKey c:codeList p:pad;
  580.         else pressKey k:keyList p:pad;
  581.     end;
  582.  
  583.     theError := ErrorHandler(ScriptError(), notErrors, v_level);
  584.     if theError[1]
  585.         thePressKey := false;
  586.     else thePressKey := true;
  587.     
  588.     if R_BeVerbose(v_level) begin
  589.         pressKeyString := "c:{codeList} k:{keyList} p:{pad}";
  590.         if not thePressKey
  591.             RIncomplete("_pressKey: Error ({theError}) pressing {thepressKeyString}",v_level);
  592.         else RStatus("_pressKey: Pressed {thepressKeyString}",v_level);
  593.     end;
  594.     
  595.     return thePressKey;
  596. end;
  597.  
  598.  
  599. #########################################################################
  600. #    task                    _releaseKey(keyList, codeList, notErrors, v_level)
  601. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  602. #    Description:    Release a list of keys and/or character codes. If target crashed,
  603. #                    always return false until gCurrentError is reset.
  604. #    Parameters:        keyList:    the keys to release
  605. #                    codeList:    the character codes to release
  606. #                    notErrors:    passed to ErrorHandler
  607. #                    pad:        use or do not use the keyPad
  608. #                    v_level:    verbosity level for reporting
  609. #    Returns:        true/false for success/failure
  610. #                    NOTE: As of VU 2.0.1, the real releaseKey does not return a value
  611. #    Examples:        if not _releaseKey({shiftKey},{20},{-1170}) println "releaseKey failed";
  612. #    Assumptions:    VU 2.0.1
  613. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  614. #    History:
  615. #        06/12/93    SBR        Created
  616. #########################################################################
  617. task    _releaseKey(    keyList := {}, codeList := {}, pad := undefined, notErrors := {}, 
  618.                         v_level := 4)
  619. begin
  620.     global gCurrentError;
  621.     
  622.     if gCurrentError begin
  623.         RIncomplete("_releaseKey: current error ({gCurrentError}) - did not try releasing",v_level);
  624.         return false;
  625.     end;
  626.     
  627.     if isUndefined(pad) begin
  628.         if codeList
  629.             if keyList releaseKey c:codeList k:keyList;
  630.             else releaseKey c:codeList;
  631.         else releaseKey k:keyList;
  632.     end;
  633.     else begin
  634.         if codeList
  635.             if keyList releaseKey c:codeList k:keyList p:pad;
  636.             else releaseKey c:codeList p:pad;
  637.         else releaseKey k:keyList p:pad;
  638.     end;
  639.     
  640.     theError := ErrorHandler(ScriptError(), notErrors, v_level);
  641.     if theError[1]
  642.         theReleaseKey := false;
  643.     else theReleaseKey := true;
  644.     
  645.     if R_BeVerbose(v_level) begin
  646.         releaseKeyString := "c:{codeList} k:{keyList} p:{pad}";
  647.         if not theReleaseKey
  648.             RIncomplete("_releaseKey: Error ({theError}) releasing {releaseKeyString}",v_level);
  649.         else RStatus("_releaseKey: Released {releaseKeyString}",v_level);
  650.     end;
  651.     
  652.     return theReleaseKey;
  653. end;
  654.  
  655.  
  656. #########################################################################
  657. #    task                    E_InitializeErrors(v_level)
  658. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  659. #    Description:    Set up an associate list in the global variable gErrorVectorTable for 
  660. #                    all known possible error values. Each item in the list is
  661. #                    { error, { taskRef, info, v_level } }
  662. #                        error: an error code from ScriptError() or any other value
  663. #                        taskRef:
  664. #                            zero: no task to call, only a string to return
  665. #                            task reference: call when this error occurs, return string
  666. #                        info:     (taskRef = 0): the string associated with this error
  667. #                                (taskRef <> 0): the parameter list for the task reference
  668. #                    You can temporarily substitute your own handler(s) by using the tasks 
  669. #                    EPushHandler() and EPopHandler(). For your custom handler the error
  670. #                    item can be an integer or any other error value you want to trap. 
  671. #                    The taskRef item can be zero or a task reference.
  672. #                    Your handler must return an error string explaining what happened.
  673. #    Parameters:        v_level:    Verbosity level for reporting.
  674. #    Returns:        true if setup worked, false if not
  675. #    Examples:        E_InitializeErrors();
  676. #    Assumptions:    VU 2.0.1
  677. #∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  678. #    History:
  679. #        06/12/93    SBR        Created
  680. #########################################################################
  681. task    E_InitializeErrors(v_level := 4)
  682. begin
  683.     global gCurrentError, gPreviousErrorStack, gErrorVectorTable, gUserErrorVectorTable,
  684.             gErrorsAreInitialized;
  685.     
  686.     gErrorsAreInitialized := false;
  687.     gCurrentError := {};            
  688.     gPreviousErrorStack := {};
  689.     gUserErrorVectorTable := {};
  690.     gErrorVectorTable := 
  691.     {
  692.         { 0,    { 0,"no error",0 } },
  693.         { -1,    { 0,"some unknown error",0 } },
  694.         { -2,    { 0,"VU program error (not a script error)",0 } },
  695.         { -1000,{ 0,"overflow",0 } },
  696.         { -1001,{ 0,"underflow",0 } },
  697.         { -1002,{ 0,"string too long",0 } },
  698.         { -1003,{ 0,"invalid operand type",0 } },
  699.         { -1004,{ 0,"invalid trait value",0 } },
  700.         { -1100,{ 0,"target failure",0 } },
  701.         { -1101,{ 0,"no descriptor available",0 } },
  702.         { -1102,{ 0,"invalid descriptor type",0 } },
  703.         { -1103,{ 0,"invalid argument to commands",0 } },
  704.         { -1104,{ 0,"no target available",0 } },
  705.         { -1105,{ 0,"match failure",0 } },
  706.         { -1106,{ 0,"command action failed",0 } },
  707.         { -1107,{ 0,"no key equivalent available for menu item",0 } },
  708.         { -1120,{ 0,"drag failed - destination off bounds",0 } },
  709.         { -1130,{ 0,"size/close/zoom failed - window inactive",0 } },
  710.         { -1140,{ 0,"size failed - new size off bounds",0 } },
  711.         { -1150,{ 0,"scroll failed - position off bounds",0 } },
  712.         { -1160,{ 0,"type/press/release keyboard operation failed",0 } },
  713.         { -1170,{ 0,"mouse operation failed",0 } },
  714.         { -1200,{ 0,"bad parameter to task call",0 } },
  715.         { -1210,{ 0,"Gestalt not available on target",0 } },
  716.         { -1220,{ 0,"no such pending external tool call",0 } },
  717.         { -1221,{ 0,"no such service for external tool",0 } },
  718.         { -1222,{ 0,"no such external tool",0 } },
  719.         { -1223,{ 0,"launch of external tool failure",0 } },
  720.         { -1230,{ 0,"could not find application with that signature (creator code)",0 } },
  721.         { -1231,{ 0,"could not launch application due to error",0 } }
  722.     };
  723.     theError := ScriptError();
  724.     if not theError begin
  725.         gErrorsAreInitialized := true;
  726.         return RStatus("E_InitializeErrors: Error system is initialized.", v_level);
  727.     end;
  728.     return RIncomplete("E_InitializeErrors: ScriptError returned {theError}", v_level);
  729. end;
  730.  
  731.